package org.zachary.commonservice.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.zachary.commonservice.entity.CreditScoreStrategy;
import org.zachary.commonservice.entity.ServiceType;

@Mapper
public interface CreditScoreStrategyMapper {

    @Select("SELECT * FROM fico.credit_score_strategy " +
            "WHERE service_name = #{serviceName} " +
            "AND #{userCreditScore} BETWEEN down AND up " +
            "LIMIT 1")
    CreditScoreStrategy getStrategy(
            @Param("serviceName") ServiceType serviceName,
            @Param("userCreditScore") int userCreditScore
    );
    @Update("UPDATE user_credit SET credit_score = #{userCreditScore} WHERE id = #{userId}")
    void updateUserCreditScore(@Param("userId") int userId, @Param("userCreditScore") int userCreditScore);
}
